#!/usr/bin/perl -w
use strict;
use warnings;

my %phone_images;
for (my $r = 0; $r < 20000; $r += 50) {
	my $url = "http://bj.ganji.com/jiaju/f$r/";
	my $content = `curl $url 2>/dev/null`;
#	print $content;
	while ($content =~ /<a href="\/jiaju\/([\w_\.]+)" target="_blank">/g) {
		$url = "http://bj.ganji.com/jiaju/$1";
#		print "\t$url\n";
		my $html = `curl -q $url 2>/dev/null`;
		if ($html =~ /<img src="\/tel\/(\w+).png" align="absmiddle"\/>/) {
			next if (defined($phone_images{$1}));
			print $1;
			for (my $i = 0; $i < length($1); $i += 4) {
				print '	'.substr($1, $i, 4);
			}
			print "\n";
			`wget -q http://bj.ganji.com/tel/$1.png -O gj_phone_img/$1.png`;
			$phone_images{$1} = 0;
		}
	}
}
